<?php
header("Content-Type: text/html;charset=utf-8");
include("config.php");

include("function.chkfun.php");

include("function.curl.php");



$THIS_TODAY_DATETIME = date('Y-m-d H:i:m',time());

$THIS_TODAY_DATE = date('Y-m-d',time());

$THIS_PHP_PAGES = strtolower($_SERVER['PHP_SELF']);

$DONT_USER_STRING = "admin,username,manage,falungong,法轮功,法轮大法";

$THIS_PAGE = strtolower($_SERVER['PHP_SELF']);





// SQL 构造类

class sqlstr{ 

	private $param = array();

	private $tablename;

	function sqlstr($tablename){

		$this -> tablename = $tablename;

	}

	public function set($name, $value, $isnum = false){

		$value = str_replace("'","'",$value); //edit $value = str_replace("'","''",$value);

		$this -> param[$name] = array($value,$isnum);

	}

	public function insertSql(){

		$keys = "";

		$values = "";

		foreach($this -> param as $key => $value){

			$keys = $keys . $key . ",";

			if($value[1]){

				$values = $values . $value[0] . ",";

			}else{

				$values = $values . "'" . $value[0] . "',";

			}

		}

		if($keys != ""){$keys = substr($keys, 0, strlen($keys)-1) ;}

		if($values != ""){$values = substr($values, 0, strlen($values)-1) ;}

		return "insert into " .$this -> tablename ."($keys) values($values)";

	}

	public function updateSql($cond){

		$group = "";

		foreach($this -> param as $key => $value){

			$group .= $key . "=";

			if($value[1]){

				$group .= $value[0] . ",";

			}else{

				$group .= "'" . $value[0] . "',";

			}

		}

		if($group != ""){$group = substr($group, 0, strlen($group)-1) ;}

		return "update " . $this -> tablename ." set $group where " . $cond;

	}

	

	public function deleteSql($cond){

		return "delete from " . $this -> tablename ." where " . $cond;

	}

}



// 无限极分类带tr样式的

function getSoonClass_tr($id,$spacestr){

	$fun_sql = "select * from kboy_bigclass where pid = $id order by bigclass_order asc, id asc";

	$fun_rows = mysql_query($fun_sql);

	$fun_nums = mysql_num_rows($fun_rows);

	if($fun_nums > 0){

		while($fun_rs = mysql_fetch_array($fun_rows)){

			echo "<form id=\"myform".$fun_rs['id']."\" name=\"myform".$fun_rs['id']."\" method=\"post\" action=\"newsaddsave.php?action=edit&id=".$fun_rs['id']."\">";

			echo "<tr bgcolor=\"#efefef\" onMouseOver=\"this.style.background='#C9C9C9'\" onMouseOut=\"this.style.background='#efefef'\" trid=\"".$fun_rs['id']."\">";

			echo "<td align=\"center\">".$fun_rs['id']."<a name=\"Anchor".$fun_rs['id']."\"></a></td>";

			echo "<td>".$spacestr."&nbsp;&nbsp;<input name=\"bigclass_cn\" type=\"text\" id=\"bigclass_cn\" value=\"".$fun_rs['bigclass_cn']."\" size=\"35\" maxlength=\"50\" /><a href=\"newsaddsave.php?action=add&id=".$fun_rs['id']."\">添子类</a></td>";

			echo "<td><input name=\"bigclass_text\" type=\"text\" id=\"bigclass_text\" value=\"".$fun_rs['bigclass_text']."\" size=\"20\" maxlength=\"50\" /></td>";

			echo "<td><input class=\"bigclass_pic_".$fun_rs['id']."\" name=\"bigclass_pic\" type=\"text\" id=\"bigclass_pic\" value=\"".$fun_rs['bigclass_pic']."\" size=\"10\" /><input class=\"image1\" type=\"button\" name=\"Submit\" value=\"上传\" mid=\"".$fun_rs['id']."\" /></td>";

			echo "<td align=\"center\"><input name=\"bigclass_urls\" type=\"text\" id=\"bigclass_urls\" value=\"".$fun_rs['bigclass_urls']."\" size=\"15\" /></td>";

			echo "<td align=\"center\"><select name=\"bigclass_menu\" id=\"bigclass_menu\">".getWebOption($fun_rs['bigclass_menu'],1)."</select></td>";

			echo "<td align=\"center\"><select name=\"bigclass_style\" id=\"bigclass_style\">".getWebOption($fun_rs['bigclass_style'],2)."</select></td>";

			echo "<td align=\"center\"><input name=\"pid\" type=\"text\" id=\"pid\" value=\"".$fun_rs['pid']."\" size=\"2\" maxlength=\"5\" onblur=\"this.value=this.value.replace(/\D/g,'')\" onkeyup=\"this.value=this.value.replace(/\D/g,'')\" onafterpaste=\"this.value=this.value.replace(/\D/g,'')\" /></td>";

			echo "<td align=\"center\"><input name=\"bigclass_order\" type=\"text\" id=\"bigclass_order\" value=\"".$fun_rs['bigclass_order']."\" size=\"2\" maxlength=\"5\" onblur=\"this.value=this.value.replace(/\D/g,'')\" onkeyup=\"this.value=this.value.replace(/\D/g,'')\" onafterpaste=\"this.value=this.value.replace(/\D/g,'')\" /></td>";

			echo "<td align=\"center\"><input type=\"submit\" name=\"Submit2\" value=\"修改\" /><a href=\"newsaddsave.php?action=del&id=".$fun_rs['id']."\">删除</a></td>";

			echo "</tr>";

			echo "</form>";

			getSoonClass_tr($fun_rs['id'],$spacestr."&nbsp;&nbsp;&nbsp;&nbsp;");

		}

	}

}





// 文本域换行空格等转换

function textareaOUT($strs){

	$strs = str_replace(chr(32),"&nbsp;",$strs);

	$strs = str_replace(chr(13),"<br>",$strs);

	//$strs = str_replace(chr(32),chr(13),$strs);

	//$strs = str_replace(chr(32),chr(13).chr(10),$strs);

	//$strs = nl2br($strs);

	$textareaOUT = $strs;

	return $textareaOUT;

}





// 下拉select的option属性

function getSoonClass_option($id,$spacestr,$selectedID,$styleID){

	if(strlen($styleID)>0){

	$fun_sql = "select * from kboy_bigclass where bigclass_style=$styleID and pid = $id order by bigclass_order asc, id asc";

	}else{

	$fun_sql = "select * from kboy_bigclass where pid = $id order by bigclass_order asc, id asc";

	}

	$fun_rows = mysql_query($fun_sql);

	$fun_nums = mysql_num_rows($fun_rows);

	if($fun_nums > 0){

		while($fun_rs = mysql_fetch_array($fun_rows)){

			$group_sql = "select * from kboy_bigclass where pid=".$fun_rs['id']." order by bigclass_order asc, id asc";

			$group_rows = mysql_query($group_sql);

			$group_nums = mysql_num_rows($group_rows);

			if($group_nums > 0){

				echo "<optgroup label=\"".$spacestr.$fun_rs['bigclass_cn']."\"></optgroup>";

			}else{

				if($selectedID == $fun_rs['id']){

					echo "<option value=\"".$fun_rs['id']."\" selected=\"selected\" msg=\"".$fun_rs['bigclass_cn']."\" >".$spacestr.$fun_rs['bigclass_cn']."</option>";

				}else{

					echo "<option value=\"".$fun_rs['id']."\" msg=\"".$fun_rs['bigclass_cn']."\" >".$spacestr.$fun_rs['bigclass_cn']."</option>";

				}

			}

				

			getSoonClass_option($fun_rs['id'],$spacestr."&nbsp;&nbsp;&nbsp;&nbsp;",$selectedID,$styleID);

		}

	}

}



// 获取选项下拉

function getWebOption($SeleID=0,$OptionID=0){

	$getWebOption = "";

	$fun_sql = "select * from kboy_weboption where option_classid=$OptionID";

	$fun_rows = mysql_query($fun_sql);

	while($fun_rs = mysql_fetch_array($fun_rows)){

		if($SeleID == $fun_rs['option_value']){

			$getWebOption = $getWebOption."<option value=\"".$fun_rs['option_value']."\" selected=\"selected\">".$fun_rs['option_name']."</option>";

		}else{

			$getWebOption = $getWebOption."<option value=\"".$fun_rs['option_value']."\">".$fun_rs['option_name']."</option>";

		}

	}

	return $getWebOption;

}



// 获取语言下拉

function getLanguage_option($languageID = 0){

	$fun_sql = "select * from kboy_language order by id";

	$fun_rows = mysql_query($fun_sql);

	while($fun_rs = mysql_fetch_array($fun_rows)){

		if($fun_rs['id'] == $languageID){

			echo "<option value=\"".$fun_rs['id']."\" selected=\"selected\">".$fun_rs['language_name']."</option>";

		}else{

			echo "<option value=\"".$fun_rs['id']."\">".$fun_rs['language_name']."</option>";

		}

	}

}





// 根据父求子

function getSoonID($id,$styleID){

	global $getSoonID;

	if(strlen($styleID)>0){

	$fun_sql = "select * from kboy_bigclass where bigclass_style=$styleID and pid = $id order by bigclass_order asc, id asc";

	}else{

	$fun_sql = "select * from kboy_bigclass where pid = $id order by bigclass_order asc, id asc";

	}

	$fun_rows = mysql_query($fun_sql);

	$fun_nums = mysql_num_rows($fun_rows);

	if($fun_nums > 0){

		while($fun_rs = mysql_fetch_array($fun_rows)){

			$getSoonID = $getSoonID .",".$fun_rs['id'];

			getSoonID($fun_rs['id'],$styleID);

		}

	}

}





// 根据子求父

function getFatherID($id,$styleID){

	global $getFatherID;

	if(strlen($styleID)>0){

	$fun_sql = "select * from kboy_bigclass where bigclass_style=$styleID and id=$id order by bigclass_order asc, id asc";

	}else{

	$fun_sql = "select * from kboy_bigclass where id=$id order by bigclass_order asc, id asc";

	}

	$fun_rows = mysql_query($fun_sql);

	$fun_nums = mysql_num_rows($fun_rows);

	if($fun_nums > 0){

		while($fun_rs = mysql_fetch_array($fun_rows)){

			$getFatherID = $getFatherID .",".$fun_rs['id'];

			getFatherID($fun_rs['pid'],$styleID);

		}

	}

}



/**

 * $count 总页数

 * $page 当前页号

 * $num 显示的页码数

 **/

function pagebar($count, $page, $num, $url) {

	$num = min($count, $num); //处理显示的页码数大于总页数的情况

	if($page > $count || $page < 1) return; //处理非法页号的情况

	$end = $page + floor($num/2) <= $count ? $page + floor($num/2) : $count; //计算结束页号

	$start = $end - $num + 1; //计算开始页号

	if($start < 1) { //处理开始页号小于1的情况

		$end -= $start - 1;

		$start = 1;

	}

	$prve = $page-1;

	$next = $page+1;

	

	echo "<li class=\"first\"><a href=\"".$url."&page=1\"><i></i>首页</a></li>";

	if($page!=1){

		echo "<li class=\"prev\"><a href=\"".$url."&page=".$prve."\">&lt;</a></li>";

	}

	for($i=$start; $i<=$end; $i++){ //输出分页条，请自行添加链接样式

		if($i == $page){

			echo "<li class=\"on\"><a href=\"".$url."&page=".$i."\">".$i."</a></li>";

		}else{

			echo "<li><a href=\"".$url."&page=".$i."\">".$i."</a></li>";

		}

	}

	if($page!=$count){

		echo "<li class=\"next\"><a href=\"".$url."&page=".$next."\">&gt;</a></li>";

	}

	echo "<li class=\"first\"><a href=\"".$url."&page=".$count."\"><i></i>尾页</a></li>";

}









//	echo '加密:'.encrypt("1", "E", $ServiceAK); 

//	echo '<br />'; 

//	echo '解密：'.encrypt("6/d7MEowAJTM", "D", $ServiceAK);

//	echo '<br />'; 

// 加密解密

function encrypt($string,$operation,$key=''){

	$key=md5($key);

	$key_length=strlen($key);

	$string=$operation=='D'?base64_decode($string):substr(md5($string.$key),0,8).$string;

	$string_length=strlen($string);

	$rndkey=$box=array();

	$result='';

	for($i=0;$i<=255;$i++){

		$rndkey[$i]=ord($key[$i%$key_length]);

		$box[$i]=$i;

	}

	for($j=$i=0;$i<256;$i++){

		$j=($j+$box[$i]+$rndkey[$i])%256;

		$tmp=$box[$i];

		$box[$i]=$box[$j];

		$box[$j]=$tmp;

	}

	for($a=$j=$i=0;$i<$string_length;$i++){

		$a=($a+1)%256;

		$j=($j+$box[$a])%256;

		$tmp=$box[$a];

		$box[$a]=$box[$j];

		$box[$j]=$tmp;

		$result.=chr(ord($string[$i])^($box[($box[$a]+$box[$j])%256]));

	}

	if($operation=='D'){

		if(substr($result,0,8)==substr(md5(substr($result,8).$key),0,8)){

			return substr($result,8);

		}else{

			return '';

		}

	}else{

		return str_replace('=','',base64_encode($result));

	}

}



// 弹出框定义

function erro($str){

	echo "<script language='javascript'>alert('".$str."');history.go(-1);</script>";

	exit();

}

function ok($str,$urls){

	echo "<script language='javascript'>alert('".$str."');location.href='".$urls."'</script>";

	exit();

}

function re($urls){

	echo "<script language='javascript'>location.href='".$urls."'</script>";

	exit();

}



// 不重复的订单号

function build_order_no(){

	return cutstr(date('YmdHis').randomkeys(6, true)."00000",20);

	// 20位订单号

	//return date('Ymd').substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 8);

}



// 截取字符串

function cutstr($str,$len){

	$tempstr = mb_substr($str,0,$len,'UTF-8');

	return $tempstr;

}





// 检测是否有特殊字符

function chkstr($string){

	if(is_array($string)){

		foreach($string as $key => $value){

			$string[$key] = chkstr($value);

		}

	}else{

		$string = $string;

	}

	return $string;

}



// 获取记录数

function getNewsNums($tablename,$wherestr){

	if(strlen($tablename)>0){

		if($wherestr != ""){

			$fun_sql = "select * from ".$tablename." where ".$wherestr;

		}else{

			$fun_sql = "select * TotalNum from ".$tablename;

		}

		$fun_rows = mysql_query($fun_sql);

		$fun_rs = mysql_fetch_array($fun_rows);

		$getNewsNums = mysql_num_rows($fun_rows);//$fun_rs['TotalNum'];

		if(empty($getNewsNums)){

			$getNewsNums = 0;

		}

		return $getNewsNums;

	}

}



// 获取名称

function getClassName($tablename,$fieldname,$wherestr=''){

	if(strlen($tablename)>0){

		if(strlen($wherestr)>0){

			$fun_sql = "select * from ".$tablename." where ".$wherestr;

		}else{

			$fun_sql = "select * from ".$tablename;

		}

//		echo "<div style=\"display:none\">";

//		echo $fun_sql;

//		echo "</div>";

		$fun_rows = mysql_query($fun_sql);

		$fun_nums = mysql_num_rows($fun_rows);
		if($fun_nums >0){

			$fun_rs=mysql_fetch_array($fun_rows);

			$getClassName = $fun_rs[$fieldname];

		}
		return $getClassName;

	}

}
// 获取最新一条数据

function getNewstime($tablename,$fieldname,$wherestr=''){

	if(strlen($tablename)>0){

		if(strlen($wherestr)>0){

			$fun_sql = "select * from ".$tablename." where ".$wherestr."order by ".$fieldname." desc limit 5";

		}else{

			$fun_sql = "select * from ".$tablename;

		}

//		echo "<div style=\"display:none\">";

//		echo $fun_sql;

//		echo "</div>";

		$fun_rows = mysql_query($fun_sql);

		$fun_nums = mysql_num_rows($fun_rows);

		if($fun_nums >0){

    		while($fun_rs=mysql_fetch_array($fun_rows)){
    		    $getNewstime['time'][] = $fun_rs[$fieldname];
    		    $getNewstime['id'][] = $fun_rs['id'];
    		}

		}

		return $getNewstime;

	}

}



// 套用标题格式

// 表名，ID，标题，截取

function getTitleStyle($tablname='kboy_news',$nid=0,$titlestr,$cutstrs=25){

	$getTitleStyle = "";

	$fun_sql = "select * from ".$tablname." where id=$nid order by news_top desc,news_order desc, id desc limit 1";

	$fun_rows = mysql_query($fun_sql);

	while($fun_rs = mysql_fetch_array($fun_rows)){

		if(!empty($news_rs['news_color'])){

			$getTitleStyle = $getTitleStyle. "<font color=\"".$fun_rs['news_color']."\">";

		}

		if(substr_count($fun_rs['news_style'],'加粗')>0){

			$getTitleStyle = $getTitleStyle. "<b>";

		}

		if(substr_count($fun_rs['news_style'],'倾斜')>0){

			$getTitleStyle = $getTitleStyle. "<i>";

		}

		if(strlen($fun_rs['news_title'])>$cutstrs){

			$getTitleStyle = $getTitleStyle. cutstr($fun_rs['news_title'],$cutstrs);

		}else{

			$getTitleStyle = $getTitleStyle. $fun_rs['news_title'];

		}

		if(substr_count($fun_rs['news_style'],'倾斜')>0){

			$getTitleStyle = $getTitleStyle. "</i>";

		}

		if(substr_count($fun_rs['news_style'],'加粗')>0){

			$getTitleStyle = $getTitleStyle. "</b>";

		}

		

		if(!empty($fun_rs['news_color'])){

			$getTitleStyle = $getTitleStyle. "</font>";

		}

	}

	return $getTitleStyle;

}







// 获取数据总和

function getAllCount($tablename,$filedname,$wherestr){

	if(strlen($tablename)>0){

		if($wherestr != ""){

			$fun_sql = "select sum(".$filedname.") as AllSum from ".$tablename." where ".$wherestr;

		}else{

			$fun_sql = "select sum(".$filedname.") as AllSum from ".$tablename;

		}

		$fun_rows = mysql_query($fun_sql);

		$fun_rs = mysql_fetch_array($fun_rows);

		$getAllCount = $fun_rs['AllSum'];

		if($getAllCount){

			$getAllCount = $fun_rs['AllSum'];

		}else{

			$getAllCount = "0";

		}

		return $getAllCount;

	}

}





// 两日期相差月份

function diffMonths($date1,$date2){ 

	$date1_stamp = strtotime($date1); 

	$date2_stamp = strtotime($date2); 

	list($date_1['y'],$date_1['m']) = explode("-",date('Y-m',$date1_stamp)); 

	list($date_2['y'],$date_2['m']) = explode("-",date('Y-m',$date2_stamp)); 

	return abs($date_1['y'] - $date_2['y']) * 12 + $date_2['m'] - $date_1['m']; 

} 



// 两日期相差天数

function diffDays($sdate,$edate){

	$second1 = strtotime(date('Y-m-d',strtotime($sdate)));

	$second2 = strtotime(date('Y-m-d',strtotime($edate)));

	if($second2 > $second1){

		$tmp = $second2;

		$second2 = $second1;

		$second1 = $tmp;

	}else{

		$second1 = 0;

		$second2 = 0;

	}

	return ($second1 - $second2) / 86400;

}

// 两时间相隔秒数

function diffSeconds($sdate,$edate){

	$second1 = strtotime($sdate);
	$second2 = strtotime($edate);
	$diffSeconds = $second2 - $second1;

	return $diffSeconds;

}





// 保留小数

function ChangeMoney($strRMB,$lenDec=2){

	$ChangeMoney = number_format($strRMB,$lenDec);

	return $ChangeMoney;

}



// 将小数转百分数

function PercentNum($strs){

	$PercentNum = $strs * 100 . "%";

	return $PercentNum;

}

// 将百分比转为小数

function XNum($strs){

	$XNum = $strs / 100;

	return $XNum;

}



// 将一些数字转换为*

function ReturnStars($NumSTR,$NumSTA=4,$NumEnd=8){

	$sLen = strlen($NumSTR);

	$Q_STR = substr($NumSTR,0,$NumSTA);

	for($k=1;$k<=($NumEnd - $NumSTA);$k++){

		$S_STR = "*".$S_STR;

	}

	$W_STR = substr($NumSTR,$NumEnd,($sLen -1) - ($NumSTA - $NumEnd));

	$ReturnStars = substr($Q_STR . $S_STR . $W_STR,0,$sLen);

	return $ReturnStars;

}





// 获取客户端IP

function getip(){

	if (getenv("HTTP_CLIENT_IP") && strcasecmp(getenv("HTTP_CLIENT_IP"), "unknown"))

	$ip = getenv("HTTP_CLIENT_IP");

	else if (getenv("HTTP_X_FORWARDED_FOR") && strcasecmp(getenv("HTTP_X_FORWARDED_FOR"), "unknown"))

	$ip = getenv("HTTP_X_FORWARDED_FOR");

	else if (getenv("REMOTE_ADDR") && strcasecmp(getenv("REMOTE_ADDR"), "unknown"))

	$ip = getenv("REMOTE_ADDR");

	else if (isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], "unknown"))

	$ip = $_SERVER['REMOTE_ADDR'];

	else

	$ip = "unknown";

	return($ip);

}





//随机生成字母数字组合随机数

function randomkeys($length,$nums = true){

	$returnStr='';

	if($nums){

		$pattern = '1234567890';

		$lennums = 9;

	}else{

		$pattern = '1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLOMNOPQRSTUVWXYZ';

		$lennums = 61;

	}

	for($i = 0; $i < $length; $i ++){

		$returnStr .= $pattern {mt_rand ( 0, $lennums )}; //生成php随机数

	}

	return $returnStr;

}



// 发送邮件

function POST_EMAIL($ToEmail,$ToTitle,$ToContent){

		$web_smtpserver = "smtp.163.com";//SMTP服务器 

		$web_smtpserverport = 25;//SMTP服务器端口 

		$web_smtpusermail = "zhijiaolaohuang@163.com";//SMTP服务器的用户邮箱 

		$web_smtpuser = "zhijiaolaohuang";//SMTP服务器的用户帐号 

		$web_smtppass = "jicheng110";//SMTP服务器的用户密码 

		

		$smtpserver = $web_smtpserver;

		$smtpserverport = $web_smtpserverport;

		$smtpusermail = $web_smtpusermail;

		$smtpuser = $web_smtpuser;

		$smtppass = $web_smtppass;

		

		$smtpemailto = $ToEmail;

		$mailsubject = $ToTitle;

		$mailbody = $ToContent;

		

		$mailtype = "HTML"; 

		$smtp = new smtp($smtpserver,$smtpserverport,true,$smtpuser,$smtppass);

		$smtp->debug = false;

		$POST_EMAIL = $smtp->sendmail($smtpemailto, $smtpusermail, $mailsubject, $mailbody, $mailtype); 

		return $POST_EMAIL;

}





// 短信验证码类

function POST_MESSAGE($Mobile,$MessageContent){

	// 30秒后可继续发送

	if(diffSeconds($_SESSION['uNowTime'],date('Y-m-d H:i:m',time()))<30){

		$POST_MESSAGE = -10;

	}else{

		$UserName = "liu10690"; // 用户名

		$PassWord = "liu10690"; // 密码

		$PostURLs = "http://qd.qxt666.cn/interface/tomsg.jsp?"; // 提交地址

		$PostSign = "【中国徒步网】";

		

		$post_data = array();

		$post_data['user'] = iconv('UTF-8', 'GBK', $UserName);

		$post_data['pwd'] = iconv('UTF-8', 'GBK', $PassWord);

		$post_data['phone'] = $Mobile;

		$post_data['msgcont'] = mb_convert_encoding($PostSign.$MessageContent, 'GBK', 'UTF-8');

		$post_len = count($post_data);

		$post_urls = "";

		$for_i = 0;

		foreach ($post_data as $k => $v){

			$for_i ++ ;

			if($for_i == $post_len){

				$post_urls .= "$k=" . $v;

			}else{

				$post_urls .= "$k=" . $v . "&";

			}

		}

		//echo $PostURLs.$post_urls;	// 测试打印地址

		$curl = new Curl();

		$POST_MESSAGE = $curl -> get($PostURLs.$post_urls);

		if($POST_MESSAGE == 0){

			$_SESSION['uMonbile'] = $Mobile;

			$_SESSION['uNowTime'] = date('Y-m-d H:i:m',time());

		}

	}

	return $POST_MESSAGE;

}



	

// 获取字符串转数组的数

function str_arraycount($str){

	if($str){

		$str = rtrim(ltrim($str,','),',');

		$str = explode(',',$str);

		$str_arraycount = count($str);

	}else{

		$str_arraycount = 0;

	}

	return $str_arraycount;

}



//// 发送站内信

//function Send_WebMail($Uid,$MTitle,$MClass,$MConents){

//	$mysql = new sqlstr("kboy_webmail"); 

//	$mysql -> set("uid",$Uid,true);

//	$mysql -> set("webmail_title",$MTitle);

//	$mysql -> set("webmail_class",$MClass);

//	$mysql -> set("webmail_content",$MConents);

//	$webmail_sql = $mysql -> insertSql();

//	$webmail_res = mysql_query($webmail_sql);

//	if(!$webmail_res){

//		echo erro("服务器内部错误09");

//	}

//}



// 获取banner

function getBanners($classids,$imgwidth=0,$imgheight=0){

	$getBanners = "";

	$WidthHeight = "";

	if($classids){

		$fun_sql = "select * from kboy_piclink where news_bigclass=$classids order by news_top desc,news_order desc, id desc limit 1";

		$fun_rows = mysql_query($fun_sql);

		while($fun_rs = mysql_fetch_array($fun_rows)){

			if($imgwidth){

				$WidthHeight = $WidthHeight ." width=\"".$imgwidth."\"";

			}

			if($imgheight){

				$WidthHeight = $WidthHeight ." width=\"".$imgheight."\"";

			}

			if($fun_rs['news_tourls']){

				$getBanners = "<a href=\"".$fun_rs['news_tourls']."\" target=\"_blank\"><img src=\"".$fun_rs['news_pic']."\"".$WidthHeight."></a>";

			}else{

				$getBanners = "<img src=\"".$fun_rs['news_pic']."\"".$WidthHeight.">";

			}

		$WidthHeight = "";

		}

	}

	return $getBanners;

}



// 字符串中是否包含某字符

function isInclude($str1,$str2){

	$arr = explode(",",trim($str1)); 

	if(in_array(trim($str2),$arr)){

		return true;

	}

}	



// 获取昵称

function getUserNickName($uid){

	if($uid){

		if(getClassName("kboy_user","user_nickname","uid=$uid")){

			$getUserNickName = getClassName("kboy_user","user_nickname","uid=$uid");

		}else{

			$getUserNickName = getClassName("kboy_user","user_email","uid=$uid");

		}

	}else{

		$getUserNickName = "";

	}

	if($getUserNickName){

		$getUserNickName =$getUserNickName;

	}else{

		$getUserNickName = getClassName("kboy_user","user_phone","uid=$uid");

	}

	return $getUserNickName;

}

// 获取头像

function getUserFace($uid){

	if($uid){

		$getUserFace = getClassName("kboy_user","user_face","uid=$uid");

	}else{

		$getUserFace = "";

	}

	return $getUserFace;

}



// 发布站内信

function webAD($wid=0,$wtitle,$wcontent,$jine){

	if($wid){

		$mysql = new sqlstr("kboy_webad"); 

		$mysql -> set("webad_title",$wtitle);

		$mysql -> set("webad_content",$wcontent);

		$mysql -> set("webad_jine",$jine);
		
		$mysql -> set("webadd_addtime",date("Y-m-d H:i:s",time()));
		
		$mysql -> set("uid",$wid);

		$news_sql = $mysql -> insertSql();

		$news_res = mysql_query($news_sql);

		if(!$news_res){

			echo erro("服务器内部错误");

		}

	}

}





function cutstr_html($string,$length=0,$ellipsis='…'){

	$string=strip_tags($string);

	$string=preg_replace('/\n/is','',$string);

	$string=preg_replace('/ |　/is','',$string);

	$string=preg_replace('/&nbsp;/is','',$string);

	preg_match_all("/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|\xe0[\xa0-\xbf][\x80-\xbf]|[\xe1-\xef][\x80-\xbf][\x80-\xbf]|\xf0[\x90-\xbf][\x80-\xbf][\x80-\xbf]|[\xf1-\xf7][\x80-\xbf][\x80-\xbf][\x80-\xbf]/",$string,$string);

	if(is_array($string)&&!empty($string[0])){

		if(is_numeric($length)&&$length){

			$string=join('',array_slice($string[0],0,$length)).$ellipsis;

		}else{

			$string=implode('',$string[0]);

		}

	}else{

		$string='';

	}

	return $string;

}





function getComList($id,$tableName,$url){

	$fun_sql = "select * from ".$tableName." where pid = $id order by id asc";

	$fun_rows = mysql_query($fun_sql);

	$fun_nums = mysql_num_rows($fun_rows);

	if($fun_nums > 0){

		echo "<div class='comments-list '>";

		echo 	"<ul>";

		while($fun_rs = mysql_fetch_array($fun_rows)){

			$pic = getClassName('kboy_user','user_face','uid='.$fun_rs['uid']);
			$tid = $fun_rs['tid'];
			if($pic){

				$member_pic = $pic;

			}else{

				$member_pic = "images/lvyou.jpg";

			}
			if($fun_rs['uid'] == 0){
				$youky = $fun_rs['youkeip']."游客"; 
			}else{
				$youky = getUserNickName($fun_rs['uid']);
			}
			echo "<li class='comments-item bor3'>";

			echo "	<div class='comments-item-bd'>";

			echo "		<div class='ui-avatar'>";

			echo "			<a href='' target='_blank'>";

			echo "				<img class='q_namecard' src='".$member_pic."'>";

			echo "			</a>";

			echo "		</div>";

			echo "		<div class='comments-content'>";

			echo "			<a class='c_tx' target='_blank' href=''>".$youky."</a>&nbsp; : ".$fun_rs['news_text'];

			echo "			<div class='comments-op'>";

			echo "				<span class=' ui-mr10 state'>".$fun_rs['news_addtime']."</span>";

			echo "				<a class='act-reply' href='javascript:;'><b class='hide-clip'>回复</b></a>";

			

			//echo "				<a class='act-delete none' href='server/test.php?action=delchildmsg'><b class='hide-clip'>删除</b></a>";

			echo "			</div>";

			echo "		</div>";

			echo "		<div class='comment-box-wrap'>";
			
			echo "		<input type='hidden' name='tid' value='$tid' />";
			
			echo "				<div class='sq-editor-cont'>";

			echo "					<div class='sq-editor-text'>";

			echo "						<textarea contenteditable='true' class='textarea text2' name='strhtml' placeholder='说点什么吧...'></textarea> ";

			echo "					</div>";

			echo "					<div class='sq-editor-ft'>";

			echo "						<div class='sq-editor-attach'>";

			echo "							<ul>";
			echo " 								<li><a href='javascript:;'>表情<span class='face-icon2' style='font-size: 22px;font-family: 微软雅黑;' >☺</span></a></li>";		
			echo "								<li><a class='btn-link-append' href='javascript:;'>超链接<i class='icon icon-link'></i></a></li>";

			echo "							</ul>";

			echo "							</div>";
			echo "						<div class='sq-editor-op'><input type='hidden' name='sonid' value='".$fun_rs['id']."' /><a href='javascript:;' class='btn-post reply1'>发表</a></div>";

			echo "					</div>";

			echo "				</div>";

			echo "		</div>";

			getComList($fun_rs['id'],$tableName,$url);
			echo "	</div>";

			
			echo "</li>";


		}

		echo 	"</ul>";

		echo "</div>";

	}

}

function getComLists($id,$tableName,$url){

	$fun_sql = "select * from ".$tableName." where pid = $id order by id asc";

	$fun_rows = mysql_query($fun_sql);

	$fun_nums = mysql_num_rows($fun_rows);

	if($fun_nums > 0){

		echo "<div class='comments-list '>";

		echo 	"<ul>";

		while($fun_rs = mysql_fetch_array($fun_rows)){

			$pic = getClassName('kboy_user','user_face','uid='.$fun_rs['uid']);

			if($pic){

				$member_pic = $pic;

			}else{

				$member_pic = "images/f_pic1_6.jpg";

			}
			if($fun_rs['uid'] == 0){
				$youky = "游客".str_replace('.', '', $fun_rs['youkeip']);
			}else{
				$youky = getUserNickName($fun_rs['uid']);
			}
			echo "<li class='comments-item bor3'>";

			echo "	<div class='comments-item-bd'>";

			echo "		<div class='ui-avatar'>";

			echo "			<a href='' target='_blank'>";

			echo "				<img class='q_namecard' src='".$member_pic."'>";

			echo "			</a>";

			echo "		</div>";

			echo "		<div class='comments-content'>";

			echo "			<a class='c_tx' target='_blank' href=''>".$youky."</a>&nbsp; : ".$fun_rs['message_text'];

			echo "			<div class='comments-op'>";

			echo "				<span class=' ui-mr10 state'>".$fun_rs['message_addtime']."</span>";

			echo "				<a class='act-reply' href='javascript:;'><b class='hide-clip'>回复</b></a>";

			

			//echo "				<a class='act-delete none' href='server/test.php?action=delchildmsg'><b class='hide-clip'>删除</b></a>";

			echo "			</div>";

			echo "		</div>";

			echo "		<div class='comment-box-wrap'>";

			echo "			<form action='".$url."?action=reply&pid=".$fun_rs['id']."' method='post'>";

			echo "				<div class='sq-editor-cont'>";

			echo "					<div class='sq-editor-text'>";

			echo "						<div contenteditable='true' class='textarea'></div>";

			echo "						<input class='textarea-hidden' type='hidden' name='strhtml' />";

			echo "					</div>";

			echo "					<div class='sq-editor-ft'>";

			echo "						<div class='sq-editor-attach'>";

			echo "							<ul>";

			echo "								<li><a class='btn-link-append' href='javascript:;'>超链接<i class='icon icon-link'></i></a></li>";

			echo "							</ul>";

			echo "							</div>";

			echo "						<div class='sq-editor-op'><a href='' class='btn-post'>发表</a></div>";

			echo "					</div>";

			echo "				</div>";

			echo "			</form>";

			echo "		</div>";

			echo "	</div>";

			echo "</li>";

			getComList($fun_rs['id'],$tableName,$url);

		}

		echo 	"</ul>";

		echo "</div>";

	}

}





function getSoonIDList($id,$tableName){

	global $getSoonIDList;

	$fun_sql = "select * from ".$tableName." where pid = $id order by id asc";

	$fun_rows = mysql_query($fun_sql);

	$fun_nums = mysql_num_rows($fun_rows);

	if($fun_nums > 0){

		while($fun_rs = mysql_fetch_array($fun_rows)){

			$getSoonIDList = $getSoonIDList .",".$fun_rs['id'];

			getSoonIDList($fun_rs['id'],$tableName);

		}

	}

}
 










// 基本信息输出

$fun_sql="select * from kboy_webinfo where id=1";

$fun_rows=mysql_query($fun_sql);

$fun_rs=mysql_fetch_array($fun_rows);

$webinfo_id = $fun_rs['id'];

$index_copy = $fun_rs['index_copy'];

$web_titles = $fun_rs['web_titles'];

$web_keywords = $fun_rs['web_keywords'];

$web_description = $fun_rs['web_description'];



$index_mk1 = $fun_rs['index_mk1'];

$index_mk2 = $fun_rs['index_mk2'];

$index_mk3 = $fun_rs['index_mk3'];

$index_mk4 = $fun_rs['index_mk4'];

$index_mk5 = $fun_rs['index_mk5'];

$index_mk6 = $fun_rs['index_mk6'];

$index_mk7 = $fun_rs['index_mk7'];

$index_mk8 = $fun_rs['index_mk8'];



// 获取ID串
function getIdList($tname='kboy_news',$filed='id',$wherestr='1=1'){
	$getIdList = "";
	$fun_sql = "select * from ".$tname." where ".$wherestr;
	$fun_rows = mysql_query($fun_sql);
	while($fun_rs = mysql_fetch_array($fun_rows)){
		$getIdList = $getIdList .',' .$fun_rs[$filed];
	}
	return lrtrim($getIdList);
}


// 去除左右逗号
function lrtrim($str){
	$str = ltrim($str,',');
	$str = rtrim($str,',');
	return $str;
}

if(strtolower($_SERVER['HTTP_HOST']) == 'cvachinawalking.com' or strtolower($_SERVER['HTTP_HOST']) == 'www.cvachinawalking.com'){

	echo "Domain not bound";

	exit();

}
//打印数据
 function sp($var){
 	echo '<pre style="background:#ddd;border-radius:5px;border:1px solid #ccc;padding:10">';
	if(is_null($var)){
		var_dump($var);
	}elseif(is_bool($var)){
		var_dump($var);
	}else{
		print_r($var);
	}
	echo '</pre>';
 }
/**
 * 定义是否ajax提交的常量
 */ 
if(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH']=='XMLHttpRequest')
{
	define("IS_AJAX", true);
}else
{
	define("IS_AJAX", false);
}
//请求服务器
	function curlget( $url ) {
		$ch = curl_init();
		curl_setopt( $ch, CURLOPT_URL, $url );
		curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
		curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, FALSE );
		curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, FALSE );

		if ( ! curl_exec( $ch ) ) {
			Log::write( curl_errno( $ch ) );
			$data = '';
		} else {
			$data = curl_multi_getcontent( $ch );
		}
		curl_close( $ch );

		return $data;
	}
	//提交POST数据
	function curl_post( $url, $postData ) {
		$ch = curl_init();
		curl_setopt( $ch, CURLOPT_URL, $url );
		curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
		curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, FALSE );
		curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, FALSE );
		curl_setopt( $ch, CURLOPT_TIMEOUT, 30 );
		curl_setopt( $ch, CURLOPT_POST, 1 );
		curl_setopt( $ch, CURLOPT_POSTFIELDS, $postData );

		if ( ! curl_exec( $ch ) ) {
			Log::write( curl_errno( $ch ) );
			$data = '';
		} else {
			$data = curl_multi_getcontent( $ch );
		}
		curl_close( $ch );

		return $data;
	}
?>